/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import POJO.PhongChieuPoJo;
import java.sql.ResultSet;

/**
 *
 * @author tran quoc thinh
 */
public class PhongChieuDAO {
    public static ResultSet LayBangPhongChieu()
    {
       MySQLDataAccessHelper helper =new MySQLDataAccessHelper();
       helper.Open();
       String sql="select * from phongchieu";
       ResultSet rs=helper.excecuteQuery(sql);       
       return rs;       
    }
      public static int ThemPhong(PhongChieuPoJo p)
    {
        MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
        helper.Open();
        String sql=String.format("INSERT INTO phongchieu (MaPhong,TenPhong,TongSoGhe)"
                + "VALUES('%s','%s',%d)",p.getMaPhong(),p.getTenPhong(),p.getTongSoVe());
        int n=helper.excecuteUpdate(sql);
        helper.Close();
        return n;
    }
     public static int SuaPhong(PhongChieuPoJo p)
    {
         MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
         helper.Open();
         String sql=String.format("UPDATE phongchieu SET TenPhong='%s',TongSoGhe='%d' WHERE MaPhong='%s'",p.getTenPhong(),p.getTongSoVe(),p.getMaPhong());
         int n=helper.excecuteUpdate(sql);
         helper.Close();
         return n;
    }
      public static int XoaPhong(String maPhong){
        
         MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
         helper.Open();
         String sql=String.format("DELETE FROM phongchieu WHERE MaPhong='%s'",maPhong);
         int n=helper.excecuteUpdate(sql);
         helper.Close();
         return n;
    }
    
}
